<template>
	<view class="container">
		<TopBtn v-if="type == 1" :title="'我的诊室'"></TopBtn>
		<TopBtn v-if="type == 2" :title="'公共诊疗室'"></TopBtn>
		<TopBtn v-if="type == 3" :title="'今日问诊'"></TopBtn>
		<view class="nav" v-if="type == 1">
			<view :class="{ act: request.status == 1 }" @click="navChange(1)">待接诊</view>
			<view :class="{ act: request.status == 2 }" @click="navChange(2)">问诊中</view>
		</view>
		<view class="nav" v-if="type == 2&&consultationSourceShow">
			<view :class="{ act: request.consultationSource == 1 }" @click="consultationSourceChange(1)">普通门诊</view>
			<view :class="{ act: request.consultationSource == 2 }" @click="consultationSourceChange(2)">专家门诊</view>
		</view>
		<view class="type">
			<view class="" @click="typeChange(1)">
				<image src="@/static/ConsultationRoom/twwz.png" mode=""></image>
				<view class="">图文问诊</view>
			</view>
			<view class="" @click="typeChange(2)">
				<image src="@/static/ConsultationRoom/yywz.png" mode=""></image>
				<view class="">语音问诊</view>
			</view>
			<view class="" @click="typeChange(3)">
				<image src="@/static/ConsultationRoom/spwz.png" mode=""></image>
				<view class="">视频问诊</view>
			</view>
		</view>
		<view class="listBox">
			<view class="list flex-sp-center" v-for="n in list" :key="n.id" @click="goinfo(n.id, n.status)">
				<image src="@/static/ConsultationRoom/tx.png" mode=""></image>
				<view class="nameBox">
					<view class="name flex-sp-center">
						<view class="flex-sp-center">
							{{ n.patientName }}
							<view class="info">{{ n.patientSex == 1 ? '男' : '女' }} | {{ n.patientAge }}岁</view>
							<view :class="n.consultationSource == 2 ? 'zjlx' : 'ptlx'">
								{{ n.consultationSourceName }}
							</view>
						</view>
						<view class="time">
							<uni-dateformat :date="n.createTime" format="yyyy-MM-dd"></uni-dateformat>
						</view>
					</view>
					<view class="text flex-center">
						<text class="ms">[病情描述]</text>
						<text class="bqms" v-if="n.consultationFormRespVO">
							{{ n.consultationFormRespVO.diseaseDescribe }}
						</text>
						<text v-else>暂未填写</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMyOutpatientInfoPage,
		getTodayAppoint,
		getPublicOutpatientInfoPage,
		getTodayOutpatientInfoPage,
	} from '@/api/ConsultationRoom'
	import {
		getDoctorSettings,
	} from '@/api/commonTools'
	export default {
		data() {
			return {
				list: [],
				request: {
					pageNo: 1,
					pageSize: 10,
					status: 1,
					consultationMethod: null,
					havePublic: '',
					consultationSource: null
				},
				maxNum: '',
				type: '',
				consultationSourceShow: false
			}
		},
		onShow() {
			let that = this
			uni.$once('show', function(data) {
				if (data) {
					that.request.pageNo = 1
					that.list = []
					that.getMyOutpatientInfoPage()
				}
			})
		},
		onUnload() {
					uni.$off()
				},
		onLoad(options) {
			if (options.type) {
				this.type = options.type
				if (options.type == 3) {
					this.request.havePublic = null
					this.request.status = 2
					this.getMyOutpatientInfoPage()
				} else if (options.type == 2) {
					this.request.havePublic = 1
					this.request.status = 1
					this.request.ignoreOut = 0
					this.getDoctorSettings()
				} else {
					this.request.havePublic = 0
					this.getMyOutpatientInfoPage()
				}
			}
		},
		onReachBottom() {
			if (this.maxNum <= this.request.pageNo) return
			this.request.pageNo = this.request.pageNo + 1
			this.getMyOutpatientInfoPage()
		},
		methods: {
			getDoctorSettings() {
				getDoctorSettings().then(res => {
					if (res.data.consultationSource == 1 || res.data.consultationSource == 2) {
						this.request.consultationSource = res.data.consultationSource
						this.getMyOutpatientInfoPage()
					} else {
						this.request.consultationSource = 1
						this.consultationSourceShow = true
						this.getMyOutpatientInfoPage()
					}
				})
			},
			consultationSourceChange(e) {
				this.request.consultationSource = e
				this.request.pageNo = 1
				this.list = []
				this.getMyOutpatientInfoPage()
			},
			typeChange(e) {
				this.request.consultationMethod = e
				this.request.pageNo = 1
				this.list = []
				this.getMyOutpatientInfoPage()
			},
			navChange(e) {
				this.request.status = e
				this.request.consultationMethod = ''
				this.request.pageNo = 1
				this.list = []
				this.getMyOutpatientInfoPage()
			},
			getMyOutpatientInfoPage() {
				if (this.type == 1) {
					getMyOutpatientInfoPage(this.request).then(res => {
						this.list.push(...res.data.list)
						let num = res.data.total / this.request.pageSize
						if (num.toString().includes('.')) {
							num = Math.ceil(num)
						}
						this.maxNum = num
					})
				}
				if (this.type == 2) {
					getPublicOutpatientInfoPage(this.request).then(res => {
						this.list.push(...res.data.list)
						let num = res.data.total / this.request.pageSize
						if (num.toString().includes('.')) {
							num = Math.ceil(num)
						}
						this.maxNum = num
					})
				}
				if (this.type == 3) {
					getTodayOutpatientInfoPage(this.request).then(res => {
						this.list.push(...res.data.list)
						let num = res.data.total / this.request.pageSize
						if (num.toString().includes('.')) {
							num = Math.ceil(num)
						}
						this.maxNum = num
					})
				}
			},
			goinfo(id, status) {
				if (status == 2) {
					if (id) {
						uni.navigateTo({
							url: `/pages/ConsultationRoom/GoConsultation/GoConsultation?id=${id}`,
						})
					}
				} else {
					if (id) {
						uni.navigateTo({
							url: `/pages/ConsultationRoom/Consultation/Consultation?id=${id}`,
						})
					}
				}
			},
		},
	}
</script>

<style lang="less" scopde>
	.flex-sp-center {
		display: flex;
		align-items: center;
	}

	.container {
		.listBox {
			margin-top: 30rpx;
			padding: 0 30rpx;

			.list {
				padding: 0 20rpx;
				box-sizing: border-box;
				width: 690rpx;
				height: 164rpx;
				background: #ffffff;
				border-radius: 20rpx;
				justify-content: space-between;
				margin-bottom: 25rpx;

				image {
					width: 90rpx;
					height: 90rpx;
					margin-right: 23rpx;
				}

				.nameBox {
					flex: 1;

					.text {
						font-weight: 500;
						font-size: 26rpx;
						color: #333;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
						margin-top: 8rpx;

						.ms {
							margin-right: 10rpx;
						}

						.bqms {
							display: inline-block;
							width: 500rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
						}
					}

					.name {
						font-weight: bold;
						font-size: 32rpx;
						color: #333333;
						justify-content: space-between;
					}

					.info {
						font-weight: 500;
						font-size: 24rpx;
						color: #666666;
						margin: 0 17rpx;
					}

					.time {
						font-size: 22rpx;
						color: #999999;
						font-weight: 500;
					}
				}
			}
		}

		.nav {
			background-color: #fff;
			font-size: 32rpx;
			color: rgba(51, 51, 51, 0.5);
			line-height: 28rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 60rpx;

			view {
				flex: 1;
				text-align: center;
			}

			.act {
				color: #333333;
				font-weight: bold;
			}
		}

		.type {
			margin-top: 18rpx;
			display: flex;
			justify-content: space-around;
			color: #333333;
			font-size: 28rpx;
			text-align: center;

			image {
				width: 139rpx;
				height: 108rpx;
			}
		}
	}
</style>